import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/net/dio_utils.dart';
import 'package:get/get.dart';

import '../../../bean/bean_train.dart';
import '../../../bean/bean_video_course.dart';

class CourseSignRecoderController extends GetxController {
  final BeanVideoCourse beanVideoCourse;
  final int trainId;

  CourseSignRecoderController(this.beanVideoCourse, this.trainId);

  bool _isLoading = true;

  bool get isLoading => _isLoading;

  List<SignRecoderBean> recoderList = [];

  Future<bool> initRequest() async {
    recoderList = [];
    //获取是否可以签到
    Map<String, dynamic> map = Map();
    map["courseId"] = beanVideoCourse.id;
    map["trainId"] = trainId;
    ResponseInfo responseInfo = await DioUtils.instance.postRequest(
      url: HttpHelper.saveOnLineSignListUrl,
      jsonMap: map,
      encrypt: true,
    );

    if (responseInfo.success) {
      if (responseInfo.data != null && responseInfo.data is List) {
        List list = responseInfo.data;
        for (int i = 0; i < list.length; i++) {
          recoderList.add(SignRecoderBean.fromMap(list[i]));
        }
      }
    } else {
      Get.defaultDialog(
          title: "提示",
          content: Text(responseInfo.message ?? "网络请求错误"),
          textCancel: "关闭");
    }

    _isLoading = false;
    update(["root"]);
  }
}
